package com.qf.smsplatform.webmaster.dto;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.qf.smsplatform.webmaster.constans.ResultCode;


@JsonInclude(JsonInclude.Include.NON_EMPTY)//加上这个注解 就不会返回空的数据了
public class R {

    private int code; //状态吗  通过定义改码 告诉客户端请求的状态
    private String msg; //状态码的描述
    private Object data; //当前返回的数据






    public static R setOk() {
        return setOk(null);
    }

    public static R setOk(Object data) {
        R r = new R();
        r.setCode(ResultCode.SUCCESS);
        r.setMsg("成功");
        r.setData(data);
        return r;
    }

    //未知的失败
    public static R setError() {
        return setError(null);
    }

    public static R setError(Object data) {

        return setError(ResultCode.FAIL,"失败",data);
    }

    public static R setError(int code, String msg, Object data) {
        R r = new R();
        r.setCode(ResultCode.SUCCESS);
        r.setCode(code);
        r.setMsg(msg);
        r.setData(data);
        return r;
    }


    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
}
